package cmd

import (
	"github.com/spf13/cobra"
	"os"
)

var Env string

func RegisterGlobalFlags(rootCmd *cobra.Command) {
	rootCmd.PersistentFlags().StringVarP(&Env, "env", "e", "", "load .yaml file, example: --env=test will use test.yaml file")
}
func RegisterDefaultCmd(rootCmd *cobra.Command, subCmd *cobra.Command) {
	cmd, _, err := rootCmd.Find(os.Args[1:])

	args := os.Args[1:]
	firstArg := ""
	if len(args) > 0 {
		firstArg = args[0]
	}
	if err == nil && cmd.Use == rootCmd.Use && firstArg != "-h" && firstArg != "--help" {
		params := append([]string{subCmd.Use}, os.Args[1:]...)
		rootCmd.SetArgs(params)
	}
}
